﻿package  core.scene {
	
	
	import base.BaseMc;
	import core.display.RankItemModule;
	import core.dialog.DialogRank;
	import core.display.LeftPreButton;
	import core.display.RightPreButton;
	import core.display.LeftNextButton;
	import core.display.RightNextButton;
	import core.display.LeftBackButton;
	import core.display.RightBackButton;
	import flash.events.MouseEvent;
	import utils.UtilScreen;
	import flash.display.MovieClip;
	
	public class SceneRank  extends BaseMc{

		private var leftPreButton: LeftPreButton;
		private var leftNextButton: LeftNextButton;
		private var rightPreButton: RightPreButton;
		private var rightNextButton: RightNextButton;
		private var leftBackButton: LeftBackButton;
		private var rightBackButton: RightBackButton;
		private var	rankDialog : DialogRank;
		private var preScene:MovieClip;
		
		
		public function SceneRank(preScene:MovieClip) {
			this.preScene = preScene;
		}
		
		//当影片放到场景上后的初始化方法
		protected override function onInit():void {
			
			var screenHeight = this.stage.stageHeight;
			var screenWidth = this.stage.stageWidth;
			trace("screenHeight:" + screenHeight);
			trace("screenWidth:"+screenWidth);
			
			rankDialog  = new DialogRank();
			this.addChild(rankDialog);
			
			leftPreButton = new LeftPreButton();
			leftPreButton.x=0;
			leftPreButton.y=screenHeight/2-leftPreButton.height -5;
			this.addChild(leftPreButton);
			
			leftNextButton = new LeftNextButton();
			leftNextButton.x=0;
			leftNextButton.y=screenHeight/2+5;
			this.addChild(leftNextButton);
			
			rightPreButton = new RightPreButton();
			rightPreButton.x= screenWidth-rightPreButton.width;
			rightPreButton.y=screenHeight/2-rightPreButton.height -5;
			this.addChild(rightPreButton);
			
			rightNextButton = new RightNextButton();
			rightNextButton.x= screenWidth-rightNextButton.width;
			rightNextButton.y=screenHeight/2 +5;
			this.addChild(rightNextButton);
			
			
			
			
			leftBackButton = new LeftBackButton();
			this.leftBackButton.scaleX = this.leftBackButton.scaleX * 0.7;
			this.leftBackButton.scaleY = this.leftBackButton.scaleY * 0.7;
			leftBackButton.x=50;
			leftBackButton.y=screenHeight-120;
			this.addChild(leftBackButton);
			
			rightBackButton = new RightBackButton();
			this.rightBackButton.scaleX = this.rightBackButton.scaleX * 0.7;
			this.rightBackButton.scaleY = this.rightBackButton.scaleY * 0.7;
			rightBackButton.x= screenWidth-120;
			rightBackButton.y=screenHeight-120;
			this.addChild(rightBackButton);
			
			
			//var screenHeight = UtilScreen.getScreenHeight();
			//var screenWidth = UtilScreen.getScreenWidth();
			
			this.leftPreButton.addEventListener(MouseEvent.CLICK,prePageClick);
			this.rightPreButton.addEventListener(MouseEvent.CLICK,prePageClick);
			
			this.leftNextButton.addEventListener(MouseEvent.CLICK,nextPageClick);
			this.rightNextButton.addEventListener(MouseEvent.CLICK,nextPageClick);
			
			this.leftBackButton.addEventListener(MouseEvent.CLICK,backClick);
			this.rightBackButton.addEventListener(MouseEvent.CLICK,backClick);
		}

		
		//当影片从场景上移除的时候周期方法 
		protected override function onRemove():void {
			this.leftPreButton.removeEventListener(MouseEvent.CLICK,prePageClick);
			this.rightPreButton.removeEventListener(MouseEvent.CLICK,prePageClick);
			
			this.leftNextButton.removeEventListener(MouseEvent.CLICK,nextPageClick);
			this.rightNextButton.removeEventListener(MouseEvent.CLICK,nextPageClick);
			
			this.leftBackButton.removeEventListener(MouseEvent.CLICK,backClick);
			this.rightBackButton.removeEventListener(MouseEvent.CLICK,backClick);
		}
		
		
		private function prePageClick(e:MouseEvent):void{
			if (rankDialog != null){
				rankDialog.setPrePageData();
			}
		}
		
		private function nextPageClick(e:MouseEvent):void{
			if (rankDialog != null){
				rankDialog.setNextPageData();
			}
		}
		
		private function backClick(e:MouseEvent):void{
			this.remove();
			if(this.preScene)
			{
				this.preScene.show();
			}
		}

	}
	
}
